package com.pinxixi.order.mapper;

import com.pinxixi.framework.domain.cart.ItemCart;
import com.pinxixi.framework.domain.order.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface OrderMapper {

    @Insert("insert into tb_order set payment=#{payment},payment_type=#{paymentType},user_id=#{userId},status=0,create_time=now(),update_time=now()")
    @Options(useGeneratedKeys = true,keyProperty = "orderId")
    void createOrder(Order order);

    @Insert("insert into tb_order_item set item_id=#{item.skuid},order_id=#{orderId},title=#{item.title},price=#{item.price},num=#{item.num}")
    void createOrderItem(ItemCart item, Long orderId);

    @Select("select order_id orderId,payment,create_time createTime from tb_order where order_id=#{id}")
    Order findOne(String id);
}
